var t = require("../../../utils/themeSkin/skinBehavior"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        num_value: "",
        UserId: "",
        tag: "",
        password: "",
        settingInfo: {
            point: 0,
            reward: !1,
            transfer: !1,
            fee_ratio: 0
        },
        show: !1,
        ecologicalName: ""
    },
    onLoad: function(t) {
        t.status && this.setData({
            tag: t.status
        }), this.setData({
            show: !1,
            num_value: ""
        }), this.getData();
    },
    allMethod: function(t) {
        this.setData({
            num_value: this.data.settingInfo.point
        });
    },
    checkNum: function(t) {
        var a = t.detail.value;
        this.setData({
            num_value: Number(a).toFixed(2)
        }), Number(this.data.num_value) <= 0 && this.setData({
            num_value: ""
        });
    },
    checkInp: function(t) {
        var a = t.detail.value;
        this.setData({
            num_value: a
        });
    },
    setTitle: function() {
        var t = this.data.ecologicalName;
        1 != this.data.tag ? 2 != this.data.tag ? 3 != this.data.tag || wx.setNavigationBarTitle({
            title: "提现".concat(t)
        }) : wx.setNavigationBarTitle({
            title: "".concat(t, "打赏")
        }) : wx.setNavigationBarTitle({
            title: "".concat(t, "转让")
        });
    },
    getData: function() {
        var t = this, i = a.getNetAddresss("plugin.ecological-point.frontend.modules.point.controllers.asset.index");
        a._postNetWork({
            url: i,
            data: {},
            success: function(a) {
                var i = a.data;
                1 == i.result ? (console.log(i.data), i.basic_info && i.basic_info.ecological_point && (t.setData({
                    ecologicalName: i.basic_info.ecological_point ? i.basic_info.ecological_point : "生态积分"
                }), t.setTitle()), t.setData({
                    settingInfo: i.data
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: t.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    bindUserId: function(t) {
        this.setData({
            UserId: t.detail.value
        });
    },
    getPostMethod: function() {
        if (1 == this.data.tag) {
            if (!this.data.num_value || 0 == this.data.num_value) return void a.tips("请输入转让数量");
            if (!this.data.UserId) return void a.tips("请输入受让人ID");
            this.data.settingInfo.transfer ? this.setData({
                show: !0,
                password: ""
            }) : this.confirmMethod();
        } else if (2 == this.data.tag) {
            if (!this.data.num_value || 0 == this.data.num_value) return void Toast("请输入打赏数量");
            if (!this.data.UserId) return void Toast("请输入打赏人ID");
            this.data.settingInfo.reward ? this.setData({
                show: !0,
                password: ""
            }) : this.confirmMethod();
        } else {
            if (!this.data.num_value || 0 == this.data.num_value) return void Toast("请输入提现数量");
            this.confirmMethod();
        }
    },
    passwordTap: function(t) {
        this.setData({
            password: t.detail
        });
    },
    confirmMethod: function() {
        var t = this, i = "", o = {};
        1 == this.data.tag || 2 == this.data.tag ? (i = 2 == this.data.tag ? "plugin.ecological-point.frontend.modules.point.controllers.reward.index" : "plugin.ecological-point.frontend.modules.point.controllers.transfer.index", 
        o = {
            amount: this.data.num_value,
            recipient_id: this.data.UserId,
            password: this.data.password
        }) : (i = "plugin.ecological-point.frontend.modules.point.controllers.withdraw.index", 
        o.amount = this.data.num_value);
        var e = a.getNetAddresss(i);
        a._postNetWork({
            url: e,
            data: o,
            success: function(i) {
                var o = i.data;
                1 == o.result ? (a.tips(o.msg), 1 == t.data.tag || 2 == t.data.tag ? t.setData({
                    password: "",
                    UserId: "",
                    num_value: ""
                }) : t.setData({
                    num_value: ""
                }), t.getData()) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = wx.getStorageSync("yz_basic_info");
        this.setData({
            ecologicalName: t.ecological_point ? t.ecological_point : "生态积分"
        }), this.setTitle();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});